#!/usr/bin/env python

import os
import re

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class RedirectBoard(webapp.RequestHandler):
  def get(self):
    self.redirect('http://rathena.org/board/')

class RedirectBugTracker(webapp.RequestHandler):
  def get(self):
    self.redirect('http://rathena.org/board/tracker/')

class RedirectBugReport(webapp.RequestHandler):
  def get(self):
    bug_id = re.search(r'^/bug/([0-9]*)/?$', os.environ['PATH_INFO'])
    self.redirect('http://rathena.org/board/index.php?app=tracker&showissue=%d' % (int(bug_id.group(1))) )

class RedirectWiki(webapp.RequestHandler):
  def get(self):
    self.redirect('http://rathena.org/wiki/')

class RedirectSVN(webapp.RequestHandler):
  def get(self):
    self.redirect('https://rathena.svn.sourceforge.net/svnroot/rathena/')

class RedirectDoxygen(webapp.RequestHandler):
  def get(self):
    self.redirect('http://rathena.org/doxygen/')

application = webapp.WSGIApplication([
  ('/board/?', RedirectBoard),
  ('/forums?/?', RedirectBoard),
  ('/bug/?', RedirectBugTracker),
  ('/bug/[0-9]*/?', RedirectBugReport),
  ('/wiki/?', RedirectWiki),
  ('/svn/?', RedirectSVN),
  ('/doxygen/?', RedirectDoxygen),
], debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()
